Package edu.uky.ai.csp.kr
Class Domain
java.lang.Object
edu.uky.ai.csp.kr.Domain
- All Implemented Interfaces:
java.lang.Cloneable,java.lang.Iterable<java.lang.Object>
public class Domain
extends java.lang.Object
implements java.lang.Iterable<java.lang.Object>, java.lang.Cloneable
A domain is the set of values that a variable might possibly be assigned.
- Author:
- Stephen G. Ware
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidadd(java.lang.Object value)Adds a potential value to the domain.Domainclone()booleancontains(java.lang.Object value)Checks if a given value is one of the possible values this variable might be assigned.java.lang.ObjectgetValue()If this domain has only 1 possible value, this method returns it.java.util.Iterator<java.lang.Object>iterator()voidremove(java.lang.Object value)Removes a potential value from the domain.voidset(java.lang.Object value)Removes all values except for a given value from the domain.intsize()Returns the number of possible values this variable might be assigned.java.lang.StringtoString()
-
Field Details
-
variable
The variable in question
-
-
Constructor Details
-
Domain
Constructs a new domain object with a given set of possible values.- Parameters:
variable- the variable to be assigned a valuevalues- a set of possible values that variable might be assigned
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
iterator
public java.util.Iterator<java.lang.Object> iterator()- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Object>
-
clone
- Overrides:
clonein classjava.lang.Object
-
size
public int size()Returns the number of possible values this variable might be assigned.- Returns:
- the number of values
-
contains
public boolean contains(java.lang.Object value)Checks if a given value is one of the possible values this variable might be assigned.- Parameters:
value- the value to test- Returns:
- true if this domain contains the given value, false otherwise
-
getValue
public java.lang.Object getValue()If this domain has only 1 possible value, this method returns it.- Returns:
- the value assigned to the variable
- Throws:
java.lang.IllegalStateException- if the domain has 0 or more than 1 possible value
-
add
public void add(java.lang.Object value)Adds a potential value to the domain.- Parameters:
value- the value to add to the set of possible values
-
remove
public void remove(java.lang.Object value)Removes a potential value from the domain.- Parameters:
value- the value to remove from the set of possible values
-
set
public void set(java.lang.Object value)Removes all values except for a given value from the domain. This effectively sets the variable's value to the given value.- Parameters:
value- the value to be retained
-